package com.xiaoshuidi.cloud.module.report.controller.bigdata;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.module.report.controller.bigdata.vo.*;
import com.xiaoshuidi.cloud.module.report.dal.DO.ApartmentDO;
import com.xiaoshuidi.cloud.module.report.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.report.service.bigdata.RentalDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import java.util.List;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;


/**
 * 租赁数据概览
 */
@Slf4j
@RestController
@RequestMapping(ApiConstants.PREFIX + "/rentalData")
@Validated
@PermitAll
public class RentalDataController {

    @Resource
    private RentalDataService rentalDataService;


    /**
     * 获取所有公寓下拉列表
     *
     * @return {@link CommonResult}<{@link List}<{@link ApartmentDO}>>
     */
    @GetMapping("/selectApartment")
    public CommonResult<List<ApartmentVO>> selectApartmentAll() {
        return success(rentalDataService.selectApartmentAll());
    }

    /**
     * 房源房态统计
     *
     * @param apartmentId
     * @return {@link CommonResult}<{@link ApartmentHouseStateStatisticsVO}>
     */
    @GetMapping("/houseStateStatisticsByAptId")
    public CommonResult<ApartmentHouseStateStatisticsVO> getHouseStateStatisticsByAptId
    (@RequestParam(value = "apartmentId", required = false) Long apartmentId) {
        return success(rentalDataService.getHouseStateStatisticsByAptId(apartmentId));
    }

    /**
     * 设备分析
     *
     * @param apartmentId 公寓id
     * @return {@link CommonResult}<{@link HouseDeviceAnalysisVO}>
     */
    @GetMapping("/getHouseDeviceAnalysis")
    public CommonResult<HouseDeviceAnalysisVO> getHouseDeviceAnalysis
    (@RequestParam(value = "apartmentId", required = false) Long apartmentId) {
        return success(rentalDataService.getHouseDeviceAnalysis(apartmentId));
    }

    /**
     * 租金分布
     *
     * @param apartmentId 公寓id
     * @return {@link CommonResult}<{@link ContractRentDistributionVO}>
     */
    @GetMapping("/contractRentDistributionByAptId")
    public CommonResult<ContractRentDistributionVO> contractRentDistributionByAptId
    (@RequestParam(value = "apartmentId", required = false) Long apartmentId) {
        return success(rentalDataService.contractRentDistributionByAptId(apartmentId));
    }

    /**
     * 付款流出占比
     *
     * @param apartmentId 公寓id
     * @return {@link CommonResult}<{@link ContractRentDistributionVO}>
     */
    @GetMapping("/paymentProportionByAptId")
    public CommonResult<ContractRentDistributionVO> paymentProportionByAptId
    (@RequestParam(value = "apartmentId", required = false) Long apartmentId) {
        return success(rentalDataService.paymentProportionByAptId(apartmentId));
    }

    /**
     * 入住人年龄分布
     *
     * @param apartmentId 公寓id
     * @return {@link CommonResult}<{@link CustomerAgeIntervalStepVO}>
     */
    @GetMapping("/customerAgeIntervalStepByAptId")
    public CommonResult<CustomerAgeIntervalStepVO> customerAgeIntervalStepByAptId
    (@RequestParam(value = "apartmentId", required = false) Long apartmentId) {
        return success(rentalDataService.customerAgeIntervalStepByAptId(apartmentId));
    }

}
